package com.ncmem.up6.biz;

import com.ncmem.up6.PathTool;
import com.ncmem.up6.database.DbFileMongodb;
import com.ncmem.up6.model.FileInf;
import com.ncmem.up6.model.ObsKeyErr;
import okhttp3.Call;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

public class Prison {
    /**
     * obskey增加后缀，通知业务层
     */
    public static void notify_keyChanged(FileInf f){
        OkHttpClient okHttpClient = new OkHttpClient();
        //http://192.168.0.1:8080/obskey/newobskey/124kb
        String url = String.format("http://10.1.81.109:8093/efile/api/saveObsKey/%s/%s/%s",
                f.obskey,
                f.obskey + PathTool.getExtention(f.nameLoc),
                f.sizeLoc);
        try {
            OkHttpClient c = new OkHttpClient();
            Request r = new Request.Builder()
                    .url(url)
                    .method("GET",null)
                    .build();
            Call call = c.newCall(r);
            Response res = call.execute();
            String body = res.body().string();

        } catch (Exception e) {
            //添加到错误表
            DbFileMongodb db = new DbFileMongodb();
            ObsKeyErr err = new ObsKeyErr();
            err.obskeyOld=f.obskey;
            err.obsKeyNew = f.obskey + PathTool.getExtention(f.nameLoc);
            err.sizeLoc = f.sizeLoc;
            db.AddObsKeyErr(err);
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}
